package com.hospital.hospitalserver.exception;

import com.hospital.hospitalserver.enums.ResultCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 自定义业务异常处理类
 * */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CustomException extends RuntimeException {
    private Integer code; //状态码
    private String msg; //系统消息

    /**
     * 通过枚举构造异常错误信息
     * */
    public CustomException(ResultCodeEnum resultCodeEnum){
        super(resultCodeEnum.getMsg());
        this.code = resultCodeEnum.getCode();
        this.msg = resultCodeEnum.getMsg();
    }

    /**
     * 支持自定义消息 1
     * */
    public CustomException(ResultCodeEnum resultCodeEnum,String customMsg){
        super(customMsg);
        this.code = resultCodeEnum.getCode();
        this.msg = resultCodeEnum.getMsg();
    }

    /**
     * 支持自定义消息 2
     * */
    public CustomException(String customMsg){
        super(customMsg);
        this.code = ResultCodeEnum.SYSTEM_ERROR.getCode();
        this.msg = ResultCodeEnum.SYSTEM_ERROR.getMsg();
    }
}
